/**
 * This file is part of Tamariba. Copyright (C) 2011 Michael Vogt <michael@tamariba.eu>, Patrick Hempel
 * <patrick@tamariba.eu>
 * 
 * Tamariba is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * Tamariba is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with Tamariba. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package eu.tamariba.html.user.client.ui;


import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.editor.client.EditorError;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import eu.tamariba.html.user.client.activity.UserDisplayActivityWrapper.View;


/**
 * @author michael
 * 
 */
public class UserDisplayView extends Composite implements View<UserDisplayView> {
	private static UserDisplayViewUiBinder uiBinder = GWT.create(UserDisplayViewUiBinder.class);
	interface UserDisplayViewUiBinder extends UiBinder<Widget, UserDisplayView> {}

	@UiField DivElement errors;
	@UiField Label status;

	
	private static UserDisplayView instance;


	public UserDisplayView() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public static UserDisplayView instance() {
		if (instance == null)
			instance = new UserDisplayView();
		return instance;
	}

	@Override
	public void showErrors(List<EditorError> errors) {
		SafeHtmlBuilder b = new SafeHtmlBuilder();
		for (EditorError error : errors) {
			b.appendEscaped(error.getPath()).appendEscaped(": ");
			b.appendEscaped(error.getMessage()).appendHtmlConstant("<br>");
		}
		this.errors.setInnerHTML(b.toSafeHtml().asString());
	}

	@Override
	public void setStatus(String status) {
		this.status.setText(status);
	}
}